/***
 * array contains
 * @param {Object} e
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
Array.prototype.contains = function(e)
{
for(var i=0;i<this.length;i++)
{
if(this[i] == e)return true;
}
return false;
}

Array.prototype.remove = function(e)
{
for(var i=0;i<this.length;i++)
{
	if(this[i] == e){
		this.splice(i,1);
	}
}
return false;
}
String.prototype.replaceAll = function(reallyDo, replaceWith, ignoreCase) {
    if (!RegExp.prototype.isPrototypeOf(reallyDo)) {
        return this.replace(new RegExp(reallyDo, (ignoreCase ? "gi": "g")), replaceWith);
    } else {
        return this.replace(reallyDo, replaceWith);
    }
}

function getSerialNumber( curr , length ){
	var curr = curr.toString();
	if( curr.length > length ) return curr;
	while( curr.length < length ){
		curr = "0" + curr;
	}
	return curr;
}

/**
 * jsonsend
 * @param {Object} url
 * @param {Object} param
 * @param {Object} callback
 */
function jsonSend( url , param , callback , async ){	
	if( async != false ){
		async = true;
	}
	$.ajax({
		url:url,
		data:param,
		type:'post',
		async:async,
	    dataType:'json',
	    success:callback
	});
}
/**
 * htmlsend
 * @param {Object} url
 * @param {Object} param
 * @param {Object} callback
 * @param {Object} container
 */
function htmlSend( url , param , container , async ){
	if( async != false ){
		async = true;
	}
	$.ajax({
		url:url,
		data:param,
		type:'post',
	   	async:async,
		success:function( data ){
			$( container ).html( data );
	    }
	});
}
function helpJump(url){
	openPage( url );
}
/* open a new page*/
function openPage(url){
	window.open(url);
}
/* forward a url */
function forward( url ){
	window.location.href = url;
}
/* confirm to redirect*/
function toconfirm( url , str ){
	if( !str ) str = "删除后将无法恢复,是否确定删除?";
	$.messager.confirm( "提示" , str , function( ok ){
		if( ok )forward( url );
	} );
}
/** go back */
function goBack(){
	history.go(-1);
	return false;
}
/** go next*/
function goNext(){
	history.go(1);
	return false;
}

/* commit */
function commit(){
	$("form").submit();
}

/* reset */
function reset(){
	$('form')[0].reset();
}
/*check validate */
function checkValidate( args ){
	var flag = true;
	for( i=0;i<args.length;i++){
		try{
			if( !$("#" + args[i]).validatebox( "isValid" ) ) flag = false;
		}catch(e){
			alert(e);
			flag = false;
		}
	}
	return flag;
}

/*check tree*/
function checkTree( treeName , ids ){
	var t = $("#" + treeName );
	var size = ids.length;
	for(i=0;i<size;i++){
		try{
			if( ids[i] == '' ) continue;
			var target = t.tree( "find" , ids[i] ).target;
			if( t.tree("isLeaf",target) ){
				t.tree( "check" , target );
			}
		}catch(e){}
	}
}

/*errorMessage*/
function errorMsg( title , content ){	
	$.messager.alert(title, "<font class='error'>" + content + "</font>"  ,"error" );
}
/*warningMessage*/
function warningMsg( title , content ){	
	$.messager.alert(title, "<font class='error'>" + content + "</font>"  ,"warning" );
}
/*infoMessage*/
function infoMsg( title , content ){	
	$.messager.alert(title, "<font class='pass'>" + content + "</font>"  ,"info" );
}

/*warningMessage*/
function questionMsg( title , content ){	
	$.messager.alert(title, content  , question );
}

/*fill select by json*/
function fillSelect( selectName , data , valueParam , nameParam , defaultSelect ){
	var select = null;
	if( typeof( selectName ) == 'string' )
		select = $( "#" + selectName );
	else
		select = $(selectName);
	select.empty();
	if( defaultSelect ){
		select.append( createOption( "" , defaultSelect ) );
	}else{
		select.append( createOption( "" , "请选择..." ) );
	}
	if( data ){
		if( data.length > 0 ){
			var length = data.length;
			for( i=0;i<length;i++){
				select.append( createOption( data[i][valueParam], data[i][nameParam] ));
			}
		}
	}
}

/*option innerHTML */
function createOption( value , name , selected ){
	return "<option value='" + value + "' " + ( selected ? selected : "" ) + ">" + name + "</option>";
}

/**remove tr */
function remove( target , base ){
	var tr = target;
	base = base ? base : 'TR';
	while( tr.tagName != base ){
		tr = tr.parentNode;
	}
	tr.parentNode.removeChild( tr );
}

function hiddenSelect(){
	$("select").hide();
}
function showSelect(){
	$("select").show();
}
/**
 * 保留小数
 * @param {Object} src
 * @param {Object} pos
 * @return {TypeName}
 */
function formatFloat(src, pos){
	if( !pos ){
		pos = 2;
	}
    return Math.round(src*Math.pow(10, pos))/Math.pow(10, pos);
}
var oldOnload = window.onload;
window.onload = function(){
	if( oldOnload ){
		oldOnload();
	}
	$('input').mouseover(function(){
		//$(this).css('background-color','blue');
	});
	$('input').mouseout(function(){
		//$(this).css('background-color','');
	});
}